define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'admin/channel/index',
        add_url: 'admin/channel/add',
        edit_url: 'admin/channel/edit',
        delete_url: 'admin/channel/delete',
        export_url: 'admin/channel/export',
        modify_url: 'admin/channel/modify',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh', 'add'],
                cols: [[
                    {field: 'id', title: 'ID', search: false},
                    {field: 'status', title: '账号状态', search: 'select', selectList: {0: '冻结', 1: '正常'}, tips: '正常|冻结', templet: ea.table.switch},
                    {field: 'name', title: '姓名'},
                    {field: 'account', title: '账号'},
                    {field: 'order_count', title: '订单总计', search: false},
                    {field: 'total_price', title: '金额总计', search: false},
                    {field: 'create_time', title: '添加时间', search: false},
                    {width: 280, title: '操作', templet: '#buttonTpl'},
                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };

    // 数据表格多删除
    $('body').on('click', '[data-table-delete-one]', function () {
        var tableId = $(this).attr('data-table-delete-one'),
            url = $(this).attr('data-url');
        url = url !== undefined ? ea.url(url) : window.location.href;
        ea.msg.confirm('确定删除？', function () {
            ea.request.post({
                url: url,
                data: {
                    id: [tableId]
                },
            }, function (res) {
                ea.msg.success(res.msg, function () {
                    layui.table.reload(init.table_render_id);
                });
            });
        });
        return false;
    });

    return Controller;
});